home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1996 April / MacFormat CD Edition MF36 (April 1996).iso / Shareware City / Developers / Tools Plus - GUI⁄Event libs / Tools Plus 2.6.1a Evaluat'n Kit / Tools Plus 2.6.1a / Tutorials / 2-Buttons on two windows / Tutorial.p < prev   
Text File  |  1995-08-25  |  8KB  |  275 lines

  1. {    Tools Plus Tutorial    - -    Buttons on two windows    }
  2.  
  3. {    NOTE:    }
  4. {    The MWERKS compiler directived ($IFC MWERKS) indicates code that is compiled only by    }
  5. {    the CodeWarrior compiler.  THINK Pascal and Metrowerks CodeWarrior Pascal have    }
  6. {    _slight_ differences, and this compiler directive lets you use one source for both compilers.    }
  7. {    You can remove the code that does not pertain to your compiler.    }
  8.  
  9.  
  10. program Tutorial;
  11.     uses
  12. {$IFC MWERKS}
  13.         Dialogs, Fonts, Processes, SegLoad, TextEdit, ToolsPlus, Windows;
  14. {$ELSEC}
  15.         ToolsPlus;
  16. {$ENDC}
  17.  
  18.  
  19.     const
  20.     {    Menu constants to make code more readable…}
  21.         ApplMenu = 0;
  22.         FileMenu = 1;
  23.         EditMenu = 2;
  24.  
  25.     {    Window constants (just to make the code readable)…    }
  26.         VendorWindow = 1;
  27.         DebuggerWindow = 2;
  28.  
  29.     {    Button constants…    }
  30.         OkButton = 255;
  31.         CancelButton = 254;
  32.  
  33.         checkSymFile = 1;
  34.         checkFullPath = 2;
  35.         checkLinkMap = 3;
  36.         checkA6 = 4;
  37.         checkDebugger = 5;
  38.  
  39.         typeAle = 1;
  40.         typeDraft = 2;
  41.         typeLager = 3;
  42.         typeLite = 4;
  43.         typeWater = 5;
  44.         levelHigh = 10;
  45.         levelMedium = 11;
  46.         levelLow = 12;
  47.  
  48.  
  49.     var
  50.         Poll: TPPollRecord;            {Polling record to retrieve event information}
  51.         ExitTheDemo: boolean;        {Should the demo terminate?}
  52.         theButton: integer;            {Button counter    }
  53.  
  54.  
  55.  
  56.  
  57. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  58.     procedure ProcessMenuSelection;
  59.         const
  60.             NewItem = 1;
  61.             OpenItem = 2;
  62.             CloseItem = 3;
  63.             QuitItem = 5;
  64.         var
  65.             theButton: integer;
  66.     begin
  67.  
  68.         case Poll.Menu.Num of
  69.             ApplMenu:     {Apple menu's 'About…' item}
  70.                 theButton := AlertBox(NoIcon, 'This is my application’s about box.  (Click to close)', NoButtonAlert);
  71.  
  72.             FileMenu: 
  73.                 case Poll.Menu.Item of
  74.                     NewItem: 
  75.                         ;
  76.                     OpenItem: 
  77.                         ;
  78.                     CloseItem: 
  79.                         ;
  80.                     QuitItem: 
  81.                         ExitTheDemo := true;
  82.                 end
  83.         end;
  84.  
  85.         MenuHilite(0);    {Turn off highlighted menu}
  86.     end;
  87.  
  88.  
  89.  
  90. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  91.     procedure DrawVendorWindow;
  92.         var
  93.             theRect: rect;
  94.             theStr: Str255;
  95.     begin
  96.     {    Draw the contents of a window.  It's good to have this code in a separate routine because you    }
  97.     {    need to use it [1] when a window is first opened, and [2] when a window needs to be refreshed.    }
  98.  
  99.         CurrentWindow(VendorWindow);    {Subsequent drawing takes place on this window (current grafPort)    }
  100.         TextFont(systemFont);
  101.         TextSize(12);
  102.  
  103.     {    Draw the 'Type' group box…    }
  104.         SetRect(theRect, 15, 18, 85, 112);
  105.         FrameRect(theRect);
  106.         SetRect(theRect, 20, 10, 56, 26);
  107.         theStr := 'Type';
  108. {$IFC MWERKS}
  109.         TETextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
  110. {$ELSEC}
  111.         TextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
  112. {$ENDC}
  113.  
  114.     {    Draw the 'Level' group box…    }
  115.         SetRect(theRect, 130, 18, 220, 85);
  116.         FrameRect(theRect);
  117.         SetRect(theRect, 135, 10, 177, 26);
  118.         theStr := 'Level';
  119. {$IFC MWERKS}
  120.         TETextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
  121. {$ELSEC}
  122.         TextBox(ptr(ord(@theStr) + 1), length(theStr), theRect, teJustCenter);
  123. {$ENDC}
  124.     end;
  125.  
  126.  
  127. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  128.     procedure ApplicationInitialization;
  129.     begin
  130.     {    Do all the application setup before you start polling for events…    }
  131.  
  132.     {    Create an Apple menu with an 'About…' item…}
  133.         AppleMenu('About My App…');
  134.  
  135.     {    Create the standard File and Edit menus…}
  136.         Menu(FileMenu, 0, enabled, 'File');
  137.         Menu(FileMenu, 1, disabled, 'New/N');
  138.         Menu(FileMenu, 2, disabled, 'Open/O');
  139.         Menu(FileMenu, 3, disabled, 'Close/W');
  140.         Menu(FileMenu, 4, disabled, mDividingLine);
  141.         Menu(FileMenu, 5, enabled, 'Quit/Q');
  142.  
  143.         Menu(EditMenu, 0, enabled, 'Edit');
  144.         Menu(EditMenu, 1, disabled, 'Undo/Z');
  145.         Menu(EditMenu, 2, disabled, mDividingLine);
  146.         Menu(EditMenu, 3, disabled, 'Cut/X');
  147.         Menu(EditMenu, 4, disabled, 'Copy/C');
  148.         Menu(EditMenu, 5, disabled, 'Paste/V');
  149.         Menu(EditMenu, 6, disabled, 'Clear');
  150.         Menu(EditMenu, 7, disabled, mDividingLine);
  151.         Menu(EditMenu, 8, disabled, 'Show Clipboard…');
  152.         UpdateMenuBar;
  153.  
  154.  
  155.     {    Create the 'Vendor' window and populate it…}
  156.         WindowOpen(VendorWindow, 0, 0, 250, 150, 'Vendor', noGrowDocProc + wTile, GoAway, NotModal);
  157.         TextFont(geneva);
  158.         TextSize(9);
  159.         NewButton(typeAle, 25, 30, 60, 42, 'Ale', radioButProc + useWFont, enabled, selected);
  160.         NewButton(typeDraft, 25, 45, 70, 57, 'Draft', radioButProc + useWFont, enabled, notSelected);
  161.         NewButton(typeLager, 25, 60, 70, 72, 'Lager', radioButProc + useWFont, enabled, notSelected);
  162.         NewButton(typeLite, 25, 75, 62, 87, 'Lite', radioButProc + useWFont, enabled, notSelected);
  163.         NewButton(typeWater, 25, 90, 70, 102, 'Water', radioButProc + useWFont, enabled, notSelected);
  164.  
  165.         NewButton(levelHigh, 140, 29, 190, 43, 'High', radioButProc, enabled, notSelected);
  166.         NewButton(levelMedium, 140, 46, 214, 60, 'Medium', radioButProc, enabled, selected);
  167.         NewButton(levelLow, 140, 63, 188, 77, 'Low', radioButProc, enabled, notSelected);
  168.  
  169.         NewButton(CancelButton, 110, 110, 167, 130, 'Cancel', pushButProc, enabled, notSelected);
  170.         NewButton(OkButton, 185, 110, 235, 130, 'Ok', pushButProc + DefaultButton, enabled, notSelected);
  171.         DrawVendorWindow;
  172.  
  173.  
  174.     {    Create the 'Debugger' window and populate it…    }
  175.         WindowOpen(DebuggerWindow, 0, 0, 250, 150, 'Debugger', noGrowDocProc + wTile, GoAway, NotModal);
  176.         NewButton(checkSymFile, 35, 10, 160, 26, 'Create SYM File', checkBoxProc, enabled, notSelected);
  177.         NewButton(checkFullPath, 53, 26, 208, 42, 'Full Path in SYM File', checkBoxProc, disabled, notSelected);
  178.         NewButton(checkLinkMap, 35, 42, 180, 58, 'Generate Link Map', checkBoxProc, enabled, notSelected);
  179.         NewButton(checkA6, 35, 58, 230, 74, 'Generate A6 Stack Frames', checkBoxProc, enabled, notSelected);
  180.         NewButton(checkDebugger, 35, 74, 200, 90, 'The Debugger™ Aware', checkBoxProc, enabled, notSelected);
  181.  
  182.         NewButton(CancelButton, 110, 110, 167, 130, 'Cancel', pushButProc, enabled, notSelected);
  183.         NewButton(OkButton, 185, 110, 235, 130, 'Ok', pushButProc + DefaultButton, enabled, notSelected);
  184.  
  185.  
  186.         ExitTheDemo := false;
  187.     end;
  188.  
  189.  
  190. {    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    }
  191. begin
  192. {$IFC MWERKS}
  193. {Toolbox initialization - - Done automatically by THINK Pascal}
  194.     InitGraf(@qd.thePort);
  195.     InitFonts;
  196.     InitWindows;
  197.     InitMenus;
  198.     TEInit;
  199.     InitDialogs(nil);
  200.     MaxApplZone;
  201. {$ENDC}
  202.  
  203.     if not InitToolsPlus(0, 2, UseColor) then
  204.         ExitToShell;
  205.  
  206.     ApplicationInitialization;
  207.  
  208.     while not ExitTheDemo do    {Main Event Loop}
  209.         if PollSystem(Poll) then    {If an event is available, process the event…}
  210.  
  211.             case Poll.What of
  212.  
  213.                 doMenu: 
  214.                     ProcessMenuSelection;
  215.  
  216.  
  217.                 doChgWindow:     {User clicked an inactive window…}
  218.                     ActivateWindow(Poll.Window);
  219.  
  220.  
  221.                 doRefresh:        {Part of window needs to be refreshed}
  222.                     begin
  223.                         BeginUpdate(WindowPointer(Poll.Window));    {Restrict drawing to area that needs it}
  224.                         if Poll.Window = VendorWindow then
  225.                             DrawVendorWindow;
  226.                         EndUpdate(WindowPointer(Poll.Window));        {End the update for the window (unrestricted drawing)}
  227.                     end;
  228.  
  229.  
  230.                 doGoAway:        {User clicked a window's close box}
  231.                     WindowClose(Poll.Window);
  232.  
  233.  
  234.                 doButton:    {    User clicked a button…    }
  235.                     begin
  236.                         CurrentWindow(Poll.Window);    {Subsequent action takes place on this window (current grafPort)    }
  237.                         if Poll.Window = VendorWindow then        {Button clicked in 'Vendor' window…    }
  238.                             case Poll.Button.Num of
  239.                                 typeAle..typeWater: 
  240.                                     for theButton := typeAle to typeWater do
  241.                                         SelectButton(theButton, Poll.Button.Num = theButton);
  242.  
  243.                                 levelHigh..levelLow: 
  244.                                     for theButton := levelHigh to levelLow do
  245.                                         SelectButton(theButton, Poll.Button.Num = theButton);
  246.  
  247.                                 OkButton, CancelButton: 
  248.                                     WindowClose(Poll.Window);
  249.                             end
  250.  
  251.                         else    {Button clicked in the 'Debugger' window…}
  252.                             case Poll.Button.Num of
  253.                                 checkSymFile..checkDebugger: 
  254.                                     begin
  255.                                         SelectButton(Poll.Button.Num, not ButtonIsSelected(Poll.Button.Num));
  256.                                         if Poll.Button.Num = checkSymFile then
  257.                                             begin
  258.                         {    'Check full path' box is available only when 'Generate SYM File' is on…    }
  259.                                                 EnableButton(checkFullPath, ButtonIsSelected(checkSymFile));
  260.                                                 if not ButtonIsEnabled(checkFullPath) then
  261.                                                     SelectButton(checkFullPath, false);
  262.                                             end
  263.                                     end;
  264.                                 OkButton, CancelButton: 
  265.                                     WindowClose(Poll.Window);
  266.                             end
  267.                     end;
  268.  
  269.  
  270.                 doPictButton, doKeyDown, doAutoKey, doClickField, doScrollBar, doListBox, doPopUpMenu, doClick: 
  271.                     ;    {Other core events we're ignoring in this app}
  272.  
  273.                 otherwise    {All other events are ignored}
  274.             end
  275. end.